package com.zjk.racing

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.util.Log
import android.view.MotionEvent
import com.zhongjinkang.basegame.game.BaseSimple3DSurfaceView
import com.zhongjinkang.basegame.game.OnGameClickListener

class TestGame(myContext: Context, onGameClickListener: OnGameClickListener) :
    BaseSimple3DSurfaceView(myContext, onGameClickListener) {

    private lateinit var  testBitmap: Bitmap
    private  var  testStr: String="hello"
    override fun initResource() {
        tip_info="请点击确认开始游戏"
        onGameClickListener.onTTs(tip_info)
        Log.e("huangjunbin","运行了")
        testBitmap=   createBitmap(resources,R.mipmap.test)

    }

    override fun customDraw(p0: Canvas?) {
     canvas.let {
         it.drawText(testStr,480f,540f,paint)
         it.drawText(testStr,960+480f,540f,paint)

         it.drawBitmap(testBitmap,435f,600f,paint)
         it.drawBitmap(testBitmap,960+445f,600f,paint)
     }
    }

    /**
     * 非主线程循环运行的时候会执行的方法
     * 这里我一般会做一些计时
     */
    override fun loopRun() {
        Thread.sleep(20)

    }

    /**
     * 游戏倒计时时间到后会执行该方法
     */
    override fun onTimeEnd() {
         onGameClickListener.onTTs("训练结束了，请按返回退出账号")
        onGameClickListener.onEnd(scoreFraction,errorFraction)
    }

    /**
     * 点击确认后，会执行该方法
     */
    override fun onStartGame() {
          tip_info="开始游戏"
          onGameClickListener.onTTs(tip_info)
    }

    /**
     * 按下
     */
    override fun onMyTouchDownEvent(p0: MotionEvent?) {
        testStr="点击了"
        //根据自己判断给予正确分和失败分
        addCorrectFraction(1)
        onGameClickListener.onScore()

//        addErrorFraction(1)
//        onGameClickListener.onError()
    }

    /**
     * 移动
     */
    override fun onMyTouchMoveEvent(p0: MotionEvent?) {
        testStr="滑动了"
    }

    /**
     * 抬起
     */
    override fun onMyTouchUpEvent(p0: MotionEvent?) {
          testStr="抬起了"
    }



    /**
     * 释放资源
     */
    override fun releaseResource() {
        if (!testBitmap.isRecycled) {
            testBitmap.recycle()
        }
    }

}